/*-------------------------------------------------------
                 Headerfiles 
---------------------------------------------------------*/
#include <REG167.H>
#include "uart.h"
#include "Decoder.h"
#include "Protokoll.h"
#include "mem_access.h"

sbit DSTATUS_LED = DP3^8;
sbit STATUS_LED = P3^8;
void Delay(int ms)
{
	int i;
	int j;
	for (i = 0; i < 300; i++)
		for (j = 0; j < ms; j++)
			;
}

unsigned int Testmemory [4];

char Testbuf[30];

void LoadTestbuf()
{
	Testbuf[0] = 0x3A;		//Binaer
	Testbuf[1] = 0x45;		//Laenge
	Testbuf[2] = 0x30;
	Testbuf[3] = 0x32;		//Steuercode
	Testbuf[4] = 0x38;
	Testbuf[5] = 0x45;		//Address LL
	Testbuf[6] = 0x30;
	Testbuf[7] = 0x33;		//Address MM
	Testbuf[8] = 0x31;
	Testbuf[9] = 0x46;		//Address HH
	Testbuf[10] = 0x30;
	Testbuf[11] = 0x34;		//Datenlaenge
	Testbuf[12] = 0x30;
	Testbuf[13] = 0x45;	 	//Checksum
	Testbuf[14] = 0x36;
	Testbuf[15] = 0x01;
	Testbuf[16] = 0x01;

	Testmemory[0] = 0x1234;
	Testmemory[1] = (unsigned int)0x0FC3;
	Testmemory[2] = (unsigned int)0xAAEE;
	Testmemory[3] = (unsigned int)0x5599;

}
void LoadTestbuf1()
{
	Testbuf[0] = 0x01;		//Binaer
	Testbuf[1] = 0x0a;		//Laenge
	Testbuf[2] = 0x03;		//Steuercode
	Testbuf[3] = 0x0E;		//Address LL
	Testbuf[4] = 0x13;		//Address MM
	Testbuf[5] = 0x0F;		//Address HH
	Testbuf[6] = 0x04;		//Datenlaenge
	Testbuf[7] = 0x43;		
	Testbuf[8] = 0xAA;
	Testbuf[9] = 0x36;		
	Testbuf[10] = 0x30;
	Testbuf[11] = 0x00;		
	Testbuf[12] = 0x00;
	Testbuf[13] = 0x01;
	Testbuf[14] = 0x01;
	Testbuf[15] = 0x01;
	Testbuf[16] = 0x01;

	Testmemory[0] = 0x1234;
	Testmemory[1] = (unsigned int)0x0FC3;
	Testmemory[2] = (unsigned int)0xAAEE;
	Testmemory[3] = (unsigned int)0x5599;
}

void main (void) 
{
	UartInit();

	DSTATUS_LED = 1;
	IEN = 1;

	LoadTestbuf1();
	while(1)
	{
		
		STATUS_LED = !STATUS_LED;
		//Protokoll(Testbuf, 11);
	}
}

